package com.tianji.promotion.cofig;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Slf4j
@Configuration
public class PromotionConfig {

    @Bean
    public Executor generateCodeExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //1-核心线程池
        executor.setCorePoolSize(2);
        //2-最大线程池大小
        executor.setMaxPoolSize(5);
        //3-队列大小
        executor.setQueueCapacity(200);
        //4-线程名称
        executor.setThreadNamePrefix("exchange-code-handler-");
        //5-拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy() );
        //6-初始化线程池
        executor.initialize();
        return executor;
    }
}
